package com.ww.word.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ww.word.R;
import com.ww.word.entity.Skin;


/**
 * @since 
 * @version 2012-11-13
 * @author wangw
 */
public class SkinAdapter extends BaseAdapter {

	private LayoutInflater mLayoutInflater;
	private List<Skin> mItemDataList;
	private int mCurSelect = -1;

	public SkinAdapter(Context context, List<Skin> itemDatalist) {
		mLayoutInflater = LayoutInflater.from(context);
		mItemDataList = itemDatalist;
	}

	@Override
	public int getCount() {
		if (mItemDataList == null) {
			return 0;
		}
		return mItemDataList.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public void setSelect(int pos) {
		if (pos >= 0 && pos < mItemDataList.size()) {
			mCurSelect = pos;
			notifyDataSetChanged();
		}

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mLayoutInflater.inflate(R.layout.activity_skin_item, null);
		}

		ImageView imageViewLeft = (ImageView) convertView.findViewById(R.id.imageLeft);
		ImageView imageViewRight = (ImageView) convertView.findViewById(R.id.imageRight);
		TextView textView = (TextView) convertView.findViewById(R.id.skinname);

		if (mItemDataList != null) {
			imageViewLeft.setImageResource(mItemDataList.get(position).getmImageViewLeftID());
			textView.setText(mItemDataList.get(position).getmTextView());
			if (position == mCurSelect) {
				imageViewRight.setVisibility(View.VISIBLE);
			} else {
				imageViewRight.setVisibility(View.GONE);
			}
		}
		return convertView;
	}

}
